<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"sekla.cn","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="两种调度算法实现FCFS每次调度从就绪队列中选择一个最先进入就绪队列的进程，要一直占据处理器进行处理直到进程完成。 按照就绪进程进入就绪队列的先后次序进行调度，简单易实现，利于长进程，CPU繁忙型作业，不利于短进程，排队时间相对过长。">
<meta property="og:type" content="article">
<meta property="og:title" content="FCFS-RR调度算法实现">
<meta property="og:url" content="http://sekla.cn/2021/11/12/os-schoollab-4/index.html">
<meta property="og:site_name" content="Sekla&#39;s Blog">
<meta property="og:description" content="两种调度算法实现FCFS每次调度从就绪队列中选择一个最先进入就绪队列的进程，要一直占据处理器进行处理直到进程完成。 按照就绪进程进入就绪队列的先后次序进行调度，简单易实现，利于长进程，CPU繁忙型作业，不利于短进程，排队时间相对过长。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/11/10/s8vePRuGF3Elp2f.png">
<meta property="article:published_time" content="2021-11-12T04:30:00.000Z">
<meta property="article:modified_time" content="2021-11-15T05:59:43.165Z">
<meta property="article:author" content="Sekla">
<meta property="article:tag" content="C++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/11/10/s8vePRuGF3Elp2f.png">

<link rel="canonical" href="http://sekla.cn/2021/11/12/os-schoollab-4/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>FCFS-RR调度算法实现 | Sekla's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script type="text/javascript" src="/js/my_js/clicklove.js"></script>
<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Sekla's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Keep Learning Keep Doing</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">100</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://sekla.cn/2021/11/12/os-schoollab-4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Sekla">
      <meta itemprop="description" content="Sekla">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sekla's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          FCFS-RR调度算法实现
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-11-12 12:30:00" itemprop="dateCreated datePublished" datetime="2021-11-12T12:30:00+08:00">2021-11-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-11-15 13:59:43" itemprop="dateModified" datetime="2021-11-15T13:59:43+08:00">2021-11-15</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">操作系统</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>8.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>8 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="两种调度算法实现"><a href="#两种调度算法实现" class="headerlink" title="两种调度算法实现"></a>两种调度算法实现</h2><h3 id="FCFS"><a href="#FCFS" class="headerlink" title="FCFS"></a>FCFS</h3><p>每次调度从就绪队列中选择一个最先进入就绪队列的进程，要一直占据处理器进行处理直到进程完成。</p>
<p>按照就绪进程进入就绪队列的先后次序进行调度，简单易实现，利于长进程，CPU繁忙型作业，不利于短进程，排队时间相对过长。</p>
<a id="more"></a>

<p><img src="https://i.loli.net/2021/11/10/s8vePRuGF3Elp2f.png" alt="image-20211110185842351"></p>
<h3 id="RR"><a href="#RR" class="headerlink" title="RR"></a>RR</h3><p>RR调度在FCFS基础上利用时间片轮转法来进行调度，则为固定时间片轮转法，按FCFS规则排队。调度程序总是分配给就绪队列队首进程，如果运行的进程用完时间片，则送回队尾重新排队，因等待而阻塞的进程送到阻塞队列，系统把被唤醒的进程送到就绪队列队尾。可变时间片轮转法，进程状态的转换方法同固定时间片轮转法，响应时间固定，时间片的长短依据进程数量的多少由 T=N×(q+t)给出的关系调整，根据进程优先级的高低进一步调整时间片， 优先级越高的进程，分配的时间片越长。</p>
<p>本次实验选用固定时间片轮转法。</p>
<!--more-->

<h3 id="算法设计"><a href="#算法设计" class="headerlink" title="算法设计"></a>算法设计</h3><p>FCFS算法由于存在阻塞，在每次FCFS调度进行，全局时间更新为当前进程的到达时间，或者上一次进程的结束时间(如果到达时，上一次进程还没有完成)，更新完全局时间之后，判断进程是否阻塞，如果阻塞就运行到知道阻塞开始，然后加入阻塞队列，不阻塞则运行到结束，然后开始下一次调度，每次循环都需要判断阻塞队列头中的阻塞结束时间和全局时间，如果当前全局时间大于等于了阻塞结束时间就需要将其出阻塞队列，入就绪队列，并更新新的到达时间和开始时间还有结束时间，每一次循环结束都需要判断比全局时间小的开始时间进程入队。</p>
<p>RR算法中，就绪队列有多少个对象，那么固定时间片就分配几个。然后再对阻塞和待加入进程进行处理，有很多条件需要判断。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;queue&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;ctime&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//进程状态</span></span><br><span class="line"><span class="keyword">enum</span> state &#123;</span><br><span class="line">    running,</span><br><span class="line">    block,</span><br><span class="line">    ready,</span><br><span class="line">    done</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//PCB结构</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">proc</span> &#123;</span></span><br><span class="line">    <span class="built_in">string</span> name;</span><br><span class="line">    <span class="keyword">int</span> pid = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">int</span> state = ready;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//简单化</span></span><br><span class="line">    <span class="keyword">double</span> arr_time = <span class="number">0</span>;<span class="comment">//到达时间</span></span><br><span class="line">    <span class="keyword">double</span> running_time = <span class="number">0</span>;<span class="comment">//周转时间</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//计算获得</span></span><br><span class="line">    <span class="keyword">double</span> start_time = <span class="number">0</span>;<span class="comment">//开始时间</span></span><br><span class="line">    <span class="keyword">double</span> end_time = <span class="number">0</span>;<span class="comment">//结束时间</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">bool</span> isblock = <span class="literal">false</span>;</span><br><span class="line">    <span class="keyword">double</span> block_time = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">double</span> bstart_time = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">double</span> bend_time = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//rr</span></span><br><span class="line">    <span class="keyword">int</span> round = <span class="number">0</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">//预创建100个进程</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">proc</span>* <span class="title">pro</span>[100];</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//进程总数</span></span><br><span class="line"><span class="keyword">int</span> proc_sum = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//进程队列</span></span><br><span class="line"><span class="built_in">queue</span>&lt;proc*&gt; qReady;</span><br><span class="line"><span class="built_in">queue</span>&lt;proc*&gt; qRun;</span><br><span class="line"><span class="built_in">queue</span>&lt;proc*&gt; qBlock;</span><br><span class="line"></span><br><span class="line"><span class="comment">//全局时间计算调度</span></span><br><span class="line"><span class="keyword">double</span> gtime = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//RR调度时间片大小</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> rrtperiod = <span class="number">0.1</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//初始化</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">rrInit</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">rr</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fcfsInit</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">procInit</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fcfs</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">procInit</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;需要进程数:&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    proc_sum = <span class="number">0</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; proc_sum;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;按行依次输入任务名 到达时间 所需运行时间 任务按输入顺序分配顺序进程号&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; proc_sum; i++) &#123;</span><br><span class="line">        pro[i] = <span class="keyword">new</span> proc;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> cnt = <span class="number">0</span>; cnt &lt; proc_sum; ++cnt) &#123;</span><br><span class="line">        <span class="built_in">cin</span> &gt;&gt; pro[cnt]-&gt;name &gt;&gt; pro[cnt]-&gt;arr_time &gt;&gt; pro[cnt]-&gt;running_time;</span><br><span class="line">        pro[cnt]-&gt;pid = cnt;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;是否需要添加阻塞?y or n&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">char</span> yon;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; yon;</span><br><span class="line">    <span class="keyword">if</span> (yon == <span class="string">&#x27;y&#x27;</span>) &#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;阻塞进程数量&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">int</span> temp_bn;</span><br><span class="line">        <span class="built_in">cin</span> &gt;&gt; temp_bn;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入需要阻塞的进程号与阻塞开始时间与阻塞时间&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">while</span> (temp_bn &gt; <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">int</span> temp_pid;</span><br><span class="line">            <span class="keyword">double</span> temp_bt, temp_bst;</span><br><span class="line">            <span class="built_in">cin</span> &gt;&gt; temp_pid &gt;&gt; temp_bst &gt;&gt; temp_bt;</span><br><span class="line">            pro[temp_pid]-&gt;isblock = <span class="literal">true</span>;</span><br><span class="line">            pro[temp_pid]-&gt;bstart_time = temp_bst;</span><br><span class="line">            pro[temp_pid]-&gt;block_time = temp_bt;</span><br><span class="line">            temp_bn--;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    procInit();</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;调度模式选择,输入FCFS或者RR：&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">string</span> mtemp;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; mtemp;</span><br><span class="line">    <span class="keyword">if</span> (mtemp == <span class="string">&quot;FCFS&quot;</span>) &#123;</span><br><span class="line">        fcfsInit();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (mtemp == <span class="string">&quot;RR&quot;</span>) &#123;</span><br><span class="line">        rrInit();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;输入错误，退出&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//FCFS</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fcfsInit</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;FCFS调度初始化中,所有进程按到达时间依次进入就绪队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="comment">//先按到达时间排序</span></span><br><span class="line">    sort(pro, pro + proc_sum , [](proc *x,  proc *y)-&gt;<span class="keyword">bool</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> x-&gt;arr_time &lt; y-&gt;arr_time;</span><br><span class="line">        &#125;);</span><br><span class="line">    <span class="comment">//初始化就绪队列</span></span><br><span class="line">    <span class="comment">//qReady.push(pro[0]);</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//开始调度</span></span><br><span class="line">    gtime += pro[<span class="number">0</span>]-&gt;arr_time;</span><br><span class="line">    fcfs();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fcfs</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> cnt = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">double</span> pre_endtime = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">        <span class="keyword">if</span> (qReady.empty()) qReady.push(pro[cnt]);</span><br><span class="line">        <span class="keyword">if</span> (qReady.front()-&gt;state == ready)</span><br><span class="line">            qRun.push(qReady.front());</span><br><span class="line">        qReady.pop();</span><br><span class="line">        <span class="keyword">if</span> (!qRun.empty()) &#123;</span><br><span class="line"></span><br><span class="line">            <span class="comment">//计算当前到达时间时前一个进程是否完成,并更新全局时间</span></span><br><span class="line">            <span class="keyword">if</span> (cnt != <span class="number">0</span> &amp;&amp; qRun.front()-&gt;arr_time &lt; pre_endtime) qRun.front()-&gt;start_time = gtime;</span><br><span class="line">            <span class="keyword">else</span> &#123;</span><br><span class="line">                qRun.front()-&gt;start_time = qRun.front()-&gt;arr_time;</span><br><span class="line">                gtime += qRun.front()-&gt;arr_time - pre_endtime;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            <span class="comment">//是否阻塞</span></span><br><span class="line">            <span class="keyword">if</span> (qRun.front()-&gt;isblock == <span class="literal">true</span>) &#123;</span><br><span class="line">                qRun.front()-&gt;state = running;</span><br><span class="line">                gtime += qRun.front()-&gt;bstart_time - qRun.front()-&gt;start_time;</span><br><span class="line">                qRun.front()-&gt;state = block;</span><br><span class="line">                qRun.front()-&gt;bend_time = qRun.front()-&gt;bstart_time + qRun.front()-&gt;block_time;</span><br><span class="line">                qBlock.push(qRun.front());</span><br><span class="line">                qRun.front()-&gt;running_time -= qRun.front()-&gt;bstart_time - qRun.front()-&gt;start_time;</span><br><span class="line">                pre_endtime = qRun.front()-&gt;bstart_time;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;进程&quot;</span> &lt;&lt; qRun.front()-&gt;name &lt;&lt; <span class="string">&quot;阻塞,加入阻塞队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">                qRun.pop();</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> &#123;</span><br><span class="line">                qRun.front()-&gt;state = running;</span><br><span class="line">                qRun.front()-&gt;end_time = qRun.front()-&gt;start_time + qRun.front()-&gt;running_time;</span><br><span class="line">                gtime += qRun.front()-&gt;running_time;</span><br><span class="line">                pre_endtime = qRun.front()-&gt;end_time;</span><br><span class="line">                qRun.front()-&gt;state = done;</span><br><span class="line">                <span class="comment">//cout</span></span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;进程&quot;</span> &lt;&lt; qRun.front()-&gt;name &lt;&lt; <span class="string">&quot;完成,开始时间:&quot;</span> &lt;&lt; qRun.front()-&gt;start_time &lt;&lt; <span class="string">&quot;结束时间&quot;</span> &lt;&lt; qRun.front()-&gt;end_time &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">                qRun.pop();</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//每个任务结束(或阻塞开始切换下个任务),查询一下把任务加入等待队列</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = cnt; i &lt; proc_sum; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (qBlock.empty()) &#123;</span><br><span class="line">                <span class="keyword">if</span> (gtime &gt;= pro[i]-&gt;arr_time &amp;&amp; pro[i]-&gt;state == ready)</span><br><span class="line">                    qReady.push(pro[i]);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (gtime + qBlock.front()-&gt;block_time &gt;= pro[i]-&gt;arr_time &amp;&amp; pro[i]-&gt;state == ready)</span><br><span class="line">                qReady.push(pro[i]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//每次调度完一个进程询问一下阻塞队列,并处理全局时间大于阻塞完成时间的进程</span></span><br><span class="line">        <span class="keyword">if</span> (!qBlock.empty()) &#123;</span><br><span class="line">            <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (gtime &gt;= qBlock.front()-&gt;bend_time || qReady.empty()) &#123;</span><br><span class="line">                    qReady.push(qBlock.front());</span><br><span class="line">                    qBlock.front()-&gt;state = ready;</span><br><span class="line">                    <span class="keyword">if</span> (qReady.empty()) gtime += qBlock.front()-&gt;block_time;</span><br><span class="line">                    qBlock.front()-&gt;arr_time = gtime;</span><br><span class="line">                    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;阻塞进程&quot;</span> &lt;&lt; qBlock.front()-&gt;name &lt;&lt; <span class="string">&quot;返回就绪队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">                    qBlock.front()-&gt;isblock = <span class="literal">false</span>;</span><br><span class="line">                    qBlock.pop();</span><br><span class="line">                    <span class="keyword">if</span> (qBlock.empty()) <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (cnt &lt; proc_sum) ++cnt;</span><br><span class="line">        <span class="keyword">if</span> ( qReady.empty() &amp;&amp; qBlock.empty()) &#123;</span><br><span class="line">            <span class="comment">//cout</span></span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;所有进程已经完成,FCFS调度完毕&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">rrInit</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;RR调度初始化中,所有进程按到达时间依次进入就绪队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="comment">//先按到达时间排序</span></span><br><span class="line">    sort(pro, pro + proc_sum - <span class="number">1</span>, []( proc* x,proc* y)-&gt;<span class="keyword">bool</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> x-&gt;arr_time &lt; y-&gt;arr_time;</span><br><span class="line">        &#125;);</span><br><span class="line">    <span class="comment">//初始化就绪队列</span></span><br><span class="line">    <span class="comment">//qReady.push(pro[0]);</span></span><br><span class="line">    <span class="comment">//开始调度</span></span><br><span class="line">    gtime += pro[<span class="number">0</span>]-&gt;arr_time;</span><br><span class="line">    <span class="comment">//rr();</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">rr</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">        <span class="keyword">int</span> cnt = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span> (qReady.empty()) qReady.push(pro[cnt]);</span><br><span class="line">        <span class="comment">//gtime</span></span><br><span class="line">        <span class="keyword">int</span> turn = qReady.size();</span><br><span class="line">        <span class="keyword">while</span> (turn) &#123;</span><br><span class="line">            <span class="keyword">if</span> (qReady.front()-&gt;state == ready &amp;&amp; qReady.front()-&gt;round &gt; <span class="number">0</span>)</span><br><span class="line">                qRun.push(qReady.front());</span><br><span class="line">            qRun.front()-&gt;state = running;</span><br><span class="line">            qRun.front()-&gt;start_time = gtime;</span><br><span class="line">            <span class="comment">//cout</span></span><br><span class="line">            qRun.front()-&gt;round = qRun.front()-&gt;running_time / rrtperiod + <span class="number">1</span>;</span><br><span class="line">            qRun.front()-&gt;end_time = qRun.front()-&gt;start_time + qRun.front()-&gt;round * rrtperiod;</span><br><span class="line">            qRun.front()-&gt;round--;</span><br><span class="line">            gtime += rrtperiod;</span><br><span class="line">            <span class="keyword">if</span> (qRun.front()-&gt;round == <span class="number">0</span>) &#123;</span><br><span class="line">                qRun.front()-&gt;state = done;</span><br><span class="line">                <span class="comment">//cout</span></span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;进程&quot;</span> &lt;&lt; qRun.front()-&gt;name &lt;&lt; <span class="string">&quot;完成,开始时间:&quot;</span> &lt;&lt; qRun.front()-&gt;start_time &lt;&lt; <span class="string">&quot;结束时间&quot;</span> &lt;&lt; qRun.front()-&gt;end_time &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (qRun.front()-&gt;isblock == <span class="literal">true</span>) &#123;</span><br><span class="line">                qBlock.push(qRun.front());</span><br><span class="line">                qRun.front()-&gt;state = block;</span><br><span class="line">                <span class="comment">//cout</span></span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;进程&quot;</span> &lt;&lt; qRun.front()-&gt;name &lt;&lt; <span class="string">&quot;阻塞,加入阻塞队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//放到队列尾</span></span><br><span class="line">            <span class="keyword">if</span> (qRun.front()-&gt;state == running) &#123;</span><br><span class="line">                qRun.front()-&gt;state = ready;</span><br><span class="line">                qReady.push(qRun.front());</span><br><span class="line">                qRun.pop();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> &#123;</span><br><span class="line">                qRun.pop();</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            --turn;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//查询待进入等待队列任务</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = cnt; i &lt; proc_sum; i++) &#123;</span><br><span class="line">            <span class="keyword">if</span> (qBlock.empty()) &#123;</span><br><span class="line">                <span class="keyword">if</span> (gtime &gt;= pro[i]-&gt;arr_time &amp;&amp; pro[i]-&gt;state == ready)</span><br><span class="line">                    qReady.push(pro[i]);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (gtime + qBlock.front()-&gt;block_time &gt;= pro[i]-&gt;arr_time &amp;&amp; pro[i]-&gt;state == ready)</span><br><span class="line">                qReady.push(pro[i]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//每次调度完一个进程询问一下阻塞队列,并处理全局时间大于阻塞完成时间的进程</span></span><br><span class="line">        <span class="keyword">if</span> (!qBlock.empty()) &#123;</span><br><span class="line">            <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (gtime &gt;= qBlock.front()-&gt;bend_time || qReady.empty()) &#123;</span><br><span class="line">                    qReady.push(qBlock.front());</span><br><span class="line">                    qBlock.front()-&gt;state = ready;</span><br><span class="line">                    <span class="keyword">if</span> (qReady.empty()) gtime += qBlock.front()-&gt;block_time;</span><br><span class="line">                    qBlock.front()-&gt;arr_time = gtime;</span><br><span class="line">                    <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;阻塞进程&quot;</span> &lt;&lt; qBlock.front()-&gt;name &lt;&lt; <span class="string">&quot;返回就绪队列&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">                    qBlock.front()-&gt;isblock = <span class="literal">false</span>;</span><br><span class="line">                    qBlock.pop();</span><br><span class="line">                    <span class="keyword">if</span> (qBlock.empty()) <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (cnt &lt; proc_sum) ++cnt;</span><br><span class="line">        <span class="keyword">if</span> ( qReady.empty() &amp;&amp; qBlock.empty()) &#123;</span><br><span class="line">            <span class="comment">//cout</span></span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">&quot;所有进程已经完成,RR调度完毕&quot;</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    init();</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; proc_sum; i++)</span><br><span class="line">        <span class="keyword">delete</span> pro[i];</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>
    
    
    

      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/C/" rel="tag"><i class="fa fa-tag"></i> C++</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/11/11/os-schoollab-3/" rel="prev" title="模拟系统时钟中断与处理">
      <i class="fa fa-chevron-left"></i> 模拟系统时钟中断与处理
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/11/14/quest-v-2/" rel="next" title="论文阅读RTSS-2014-Quest-V分离内核中的通信与迁移(2)可预测通信与迁移">
      论文阅读RTSS-2014-Quest-V分离内核中的通信与迁移(2)可预测通信与迁移 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%A4%E7%A7%8D%E8%B0%83%E5%BA%A6%E7%AE%97%E6%B3%95%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.</span> <span class="nav-text">两种调度算法实现</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#FCFS"><span class="nav-number">1.1.</span> <span class="nav-text">FCFS</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RR"><span class="nav-number">1.2.</span> <span class="nav-text">RR</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1"><span class="nav-number">1.3.</span> <span class="nav-text">算法设计</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Sekla"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Sekla</p>
  <div class="site-description" itemprop="description">Sekla</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">100</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ShenTiao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ShenTiao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:584892986@qq.com" title="E-Mail → mailto:584892986@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

      <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1416875904&auto=0&height=66"></iframe>
      
    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Sekla</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">288k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4:22</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":250,"height":500},"mobile":{"show":false},"react":{"opacity":0.9},"log":false});</script></body>
</html>

<script type="text/javascript" src="/js/src/love.js"></script>
